//
//  BaiduMapMudule.m
//  WeiWeiGou
//
//  Created by Liralife on 2017/6/7.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "BaiduMapMudule.h"

#import "RCTBridgeModule.h"
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "RCTBridge.h"
#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件

@interface BaiduMapMudule ()<RCTBridgeModule>
{
  
}
@end

@implementation BaiduMapMudule
RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(getLatLongData:(RCTResponseSenderBlock)callback)
{

  NSArray * lacationList = [[NSUserDefaults standardUserDefaults]objectForKey:@"lacationList"];

  callback(lacationList);
  
}
#pragma mark ------------------------------ 导航 - 百度
RCT_EXPORT_METHOD(onDaoHangForBaiDuMapLat:(NSString *)startLat Lon:(NSString *)startLon endLat:(NSString *)endLat endLon:(NSString *)endLon :(RCTResponseSenderBlock)callback)
{
  //    百度地图如何调起APP进行导航
  //    mode  导航模式，固定为transit、driving、walking，分别表示公交、驾车和步行
  NSString * modeBaiDu = @"driving";
  switch (2) {
    case 1:
    {
      modeBaiDu = @"transit";
    }
      break;
    case 2:
    {
      modeBaiDu = @"driving";
    }
      break;
    case 3:
    {
      modeBaiDu = @"walking";
    }
      break;
      
    default:
      break;
  }
  

  NSString *url = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%@,%@&destination=%@,%@&mode=%@&src=公司|APP",startLat,startLon,endLat,endLon,modeBaiDu] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;
  
  //    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  
  if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]])// -- 使用 canOpenURL 判断需要在info.plist 的 LSApplicationQueriesSchemes 添加 baidumap 。
  {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  }else{
    [[[UIAlertView alloc]initWithTitle:@"没有安装百度地图" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
  }
  
}


@end
